package disorderly;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public enum Status {
	NOT_IN_LIST(0, "-", 0),
	INVITED(1, "i", 0),
	ACCEPTED(2, "a", 0),
	DECLINED(3, "D", 0),
	CONFIRMED(4, "C", 1),
	OUT(5, "o", 0),
	STANDBY(6, "S", 1),
	_(7, "", 0),
	__(8, "", 0),
	TENTATIVE(9, "t", 0),
	___(10, "", 0);

	private static final Map<Integer, Status> m;

	private Integer status;
	private String name;
	private Integer attendanceValue;

	static {
		HashMap<Integer, Status> map = new HashMap<Integer, Status>();
		for (Status s : values()) {
			map.put(s.status, s);
		}
		m = Collections.unmodifiableMap(map);
	}

	public Integer getStatus() {
		return status;
	}

	public String getName() {
		return name;
	}

	public Integer getAttendanceValue() {
		return attendanceValue;
	}

	private Status(Integer status, String name, Integer attendanceValue) {
		this.status = status;
		this.name = name;
		this.attendanceValue = attendanceValue;
	}

	public static Status fromAttendance(Attendance at) {
		if (at == null || at.InviteStatus == -1) {
			return NOT_IN_LIST;
		}
		return m.get(at.InviteStatus);
	}
}
